<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>商家优惠券数据报表</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport"
          content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
    <link rel="stylesheet" href="/public/layuiadmin/layui/css/layui.css" media="all">
    <link rel="stylesheet" href="/public/layuiadmin/style/admin.css" media="all">
    <script src="/public/js/exportExcel.js"></script>
</head>
<body>

<div class="layui-fluid">
    <div class="layui-col-md12">
        <div class="layui-card">
            <div class="layui-tab layui-tab-card" lay-filter="component-tabs-brief">
                <ul class="layui-tab-title">
                    <li class="layui-this" lay-id="tab1">日报表</li>
                    <li lay-id="tab2">月报表</li>
                </ul>
                <div class="layui-tab-content">
                    <div class="layui-tab-item layui-show">
                        <!-- 日报表 -->
                        <div class="layui-form layui-card-header layuiadmin-card-header-auto">
                            <div class="layui-form-item">

                                <blockquote class="layui-elem-quote layui-quote-nm">
                                    <div style="font-size: 18px;height: 30px"><b>${merchantName} ---- ${couponName} 商家优惠券数据报表</b></div>
                                    <div style="font-size: 15px">备注：导出明细是以<b>领取数量</b>的数据</div>
                                </blockquote>

                                <div class="layui-inline">
                                    <label class="layui-form-label">时间</label>
                                    <div class="layui-input-block">
                                        <div class="layui-inline">
                                            <input type="text" class="layui-input" id = "time1" autocomplete="off">
                                        </div>
                                    </div>
                                </div>

                                <input type="hidden" id="year1" name="year" value="">
                                <input type="hidden" id="month" name="month" value="">

                                <div class="layui-inline">
                                    <button class="layui-btn layuiadmin-btn-useradmin" lay-submit lay-filter="LAY-search1">
                                        <i class="layui-icon  layuiadmin-button-btn"> 查询</i>
                                    </button>
                                </div>
                            </div>
                        </div>

                    #{if toolsUtils.checkBtn('/merchant/getListByMonth')} <table class="layui-hide" id="test-table-reload1" lay-filter="test-table-reload1"></table> #{/if}

                        <script type="text/html" id="test-table-reload-barDemo1">
                            <a class="layui-btn layui-btn-normal layui-btn-xs #{if !toolsUtils.checkBtn('/export/exportDayCouponList')} layui-hide #{/if}" lay-event="exportDay"><i class="layui-icon layui-icon-download-circle"></i>导出明细</a>
                        </script>
                    </div>

                    <!-- 月报表 -->
                    <div class="layui-tab-item">

                        <div class="layui-form layui-card-header layuiadmin-card-header-auto">
                            <div class="layui-form-item">

                                <blockquote class="layui-elem-quote layui-quote-nm">
                                    <div style="font-size: 18px;height: 30px"><b>${merchantName} ---- ${couponName} 商家优惠券数据报表</b></div>
                                    <div style="font-size: 15px"> 备注：导出明细是以<b>使用数量</b>的数据</div>
                                </blockquote>

                                <div class="layui-inline">
                                    <label class="layui-form-label">时间</label>
                                    <div class="layui-input-block">
                                        <div class="layui-inline">
                                            <input type="text" class="layui-input" id="time2" autocomplete="off">
                                        </div>
                                    </div>
                                </div>

                                <input type="hidden" id="year2" name="year" value="">

                                <div class="layui-inline">
                                    <button class="layui-btn layuiadmin-btn-useradmin" lay-submit lay-filter="LAY-search2">
                                        <i class="layui-icon layuiadmin-button-btn"> 查询</i>
                                    </button>
                                </div>
                            </div>
                        </div>


                    #{if toolsUtils.checkBtn('/merchant/getListByYear')} <table class="layui-hide" id="test-table-reload2" lay-filter="test-table-reload2"></table> #{/if}

                        <script type="text/html" id="test-table-reload-barDemo2">
                            <a class="layui-btn layui-btn-normal layui-btn-xs #{if !toolsUtils.checkBtn('/export/exportMonthCouponList')} layui-hide #{/if}" lay-event="exportMonth"><i class="layui-icon layui-icon-download-circle"></i>导出明细</a>
                        </script>
                    </div>
                    </div>

                </div>
            </div>
        </div>
    </div>
</div>
<input type="hidden" id="couponId" value="${couponId}">
<script src="/public/layuiadmin/layui/layui.js"></script>
<script>
    layui.config({
        base: '/public/layuiadmin/' //静态资源所在路径
    }).extend({
        index: 'lib/index' //主入口模块
    }).use(['index', 'table', 'utils', 'form', 'laydate', 'util'], function () {
        var $ = layui.$,
                table = layui.table,
                form = layui.form,
                util = layui.util,
                laydate = layui.laydate,
                element = layui.element,
                admin = layui.admin;

        //时间选择器
        laydate.render({
            elem: '#time1'
            , theme: 'molv'
            , value: new Date().getFullYear() + '-' + util.digit((new Date().getMonth()+1), 2)
            , type: 'month'
            , done: function(value, date){
                $("#year1").val(date.year);
                $("#month").val(date.month);
            }
        });

        laydate.render({
            elem: '#time2'
            , theme: 'molv'
            , value: new Date().getFullYear()
            , type: 'year'
            , done: function(value, date){
                $("#year2").val(date.year);
            }
        });

        //监听Tab1搜索
        form.on("submit(LAY-search1)", function (data) {
            var field = data.field;

            //执行重载
            table.reload('test-table-reload1', {
                where: field
            });
        });
        //监听Tab2搜索
        form.on("submit(LAY-search2)", function (data) {
            var field = data.field;

            //执行重载
            table.reload('test-table-reload2', {
                where: field
            });
        });

        /* 监听Tab1 日报表 */
        table.render({
            elem: '#test-table-reload1'
            , url: "/merchant/getListByMonth?couponId=" + $("#couponId").val()
            , toolbar: '#test-table-reload-toolbar2'
            , defaultToolbar: ['filter']
            , cellMinWidth: 80
            , cols: [[
                {title: '日期', templet: function (d) {
                        return "<div>" + d.year + "-" + util.digit(d.month, 2) + "-" + util.digit(d.day, 2)  + "</div>";
                    }}
                , {field: 'dispatchCount', title: '领取数量' , sort: true}
                , {field: 'donateCount', title: '已赠送数量', sort: true}
                , {field: 'usedCount', title: '使用数量', sort: true}
                , {fixed: 'right', title: '操作', toolbar: '#test-table-reload-barDemo1', width: 160}
            ]]
            , page: true
            , height: 522
        });

        /* 监听Tab2 月报表 */
        table.render({
            elem: '#test-table-reload2'
            , url: "/merchant/getListByYear?couponId=" + $("#couponId").val()
            , toolbar: '#test-table-reload-toolbar2'
            , defaultToolbar: ['filter']
            , cellMinWidth: 80
            , cols: [[
                {title: '月份', templet: function (d) {
                        return "<div>" + d.year + "-" + util.digit(d.month, 2) + "</div>";
                    }}
                , {field: 'dispatchCount', title: '领取数量', sort: true}
                , {field: 'donateCount', title: '已赠送数量', sort: true}
                , {field: 'usedCount', title: '使用数量', sort: true}
                , {fixed: 'right', title: '操作', toolbar: '#test-table-reload-barDemo2', width: 160}
            ]]
            , page: true
            , height: 522
        });

        table.on('tool(test-table-reload1)', function(obj){
            var data = obj.data;
            if(obj.event === 'exportDay'){
                exportApi("exportCouponList","day",data.year + "-" + util.digit(data.month, 2) + "-" + util.digit(data.day, 2))
            }
        });

        table.on('tool(test-table-reload2)', function(obj){
            var data = obj.data;
            if(obj.event === 'exportMonth'){
                exportApi("exportCouponList","month",data.year + "-" + util.digit(data.month, 2));
            }
        });

    });
</script>
</body>
</html>